package org.iabako.shared.entity.enumeration;

import org.iabako.client.tools.Messages;

/**
 * Created by jose on 12/12/14.
 */
public enum IabakoPackage implements LabelEnum {

    freeOneMonth("package_free_1_months", null, null, 0, 1, 5000, 100, 30),
    free("package_free_3_months", null, null, 0, 3, 5000, 100, 30),
    starterMonthly("package_starter_monthly", "package_starter_monthly_paypal", "AHBAXS2TU5NAE", 9, 1, 100, 0, 0),
    starterAnnual("package_starter_yearly", "package_starter_yearly_paypal", "DHJYZK2F96SXW", 99, 12, 100, 0, 0),
    proMonthly("package_pro_monthly", "package_pro_monthly_paypal", "ZGKPG7ZBVGNQY", 19, 1, 500, 10, 10),
    proAnnual("package_pro_yearly", "package_pro_yearly_paypal", "RBUKSC2HZ5FWE", 209, 12, 500, 10, 10),
    enterpriseMonthly("package_enterprise_monthly", "package_enterprise_monthly_paypal", "LCJ8BPUHMUL8E", 29, 1, 5000, 100, 30),
    enterpriseAnnual("package_enterprise_yearly", "package_enterprise_yearly_paypal", "QP8WPHLUEY5SU", 319, 12, 5000, 100, 30);

    String labelKey;
    String paypalLabelKey;
    String paypalButtonID;
    double amount;
    int timeInMonths;

    Integer invoiceLimit;
    Integer communicationsLimit;
    Integer customFieldLimit;

    IabakoPackage(String labelKey, String paypalLabelKey, String paypalButtonID, double amount, int timeInMonths,
                  Integer invoiceLimit, Integer communicationsLimit, Integer customFieldLimit) {
        this.labelKey = labelKey;
        this.paypalLabelKey = paypalLabelKey;
        this.paypalButtonID = paypalButtonID;
        this.amount = amount;
        this.timeInMonths = timeInMonths;
        this.invoiceLimit = invoiceLimit;
        this.communicationsLimit = communicationsLimit;
        this.customFieldLimit = customFieldLimit;
    }

    public String getLabel() {
        return Messages.getLabel(labelKey);
    }

    public String getPaypalLabel() {
        return Messages.getLabel(paypalLabelKey);
    }

    public String getLabelKey() {
        return labelKey;
    }

    public String getPaypalButtonID() {
        return paypalButtonID;
    }

    public double getAmount() {
        return amount;
    }

    public int getTimeInMonths() {
        return timeInMonths;
    }

    public Integer getInvoiceLimit() {
        return invoiceLimit;
    }

    public Integer getCommunicationLimit() {
        return communicationsLimit;
    }

    public Integer getCustomFieldLimit() {
        return customFieldLimit;
    }

    public static IabakoPackage getPartner(IabakoPackage iabakoPackage) {
        switch (iabakoPackage) {
            case starterMonthly:
                return IabakoPackage.starterAnnual;
            case starterAnnual:
                return IabakoPackage.starterMonthly;
            case proMonthly:
                return IabakoPackage.proAnnual;
            case proAnnual:
                return IabakoPackage.proMonthly;
            case enterpriseMonthly:
                return IabakoPackage.enterpriseAnnual;
            case enterpriseAnnual:
                return IabakoPackage.enterpriseMonthly;
        }
        return null;
    }

    public String getShortLabel() {
        return isFree() ? getLabel() : getLabel().substring(0, getLabel().indexOf(" "));
    }

    public boolean isFree() {
        return this == IabakoPackage.free || this == IabakoPackage.freeOneMonth;
    }

    public boolean isStarter() {
        return this == IabakoPackage.starterMonthly || this == IabakoPackage.starterAnnual;
    }

    public boolean isPro() {
        return this == IabakoPackage.proMonthly || this == IabakoPackage.proAnnual;
    }

    public boolean isEnterprise() {
        return this == IabakoPackage.enterpriseMonthly || this == IabakoPackage.enterpriseAnnual;
    }
}
